<template>
<div >
<!--  喜欢页面-->
  <el-table
    :data="userLike.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
    style="width: 100%">
    <el-table-column
      label="名字"
      prop="name">
    </el-table-column>
    <el-table-column
      label="性别"
      prop="sex">
    </el-table-column>
    <el-table-column
      label="出生日期"
      prop="birthday">
    </el-table-column>
    <el-table-column
      label="公司"
      prop="company">
    </el-table-column>
    <el-table-column
      label="职位"
      prop="position">
    </el-table-column>
    <el-table-column
      label="手机"
      prop="mobile">
    </el-table-column>
    <el-table-column
      label="浏览量"
      prop="visitied">
    </el-table-column>
    <el-table-column
      align="right">
      <template slot="header" slot-scope="scope">
        <el-input
          v-model="search"
          size="mini"
          placeholder="输入关键字搜索"/>
      </template>
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)" >删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!--    分页-->
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</div>
</template>

<script>
export default {
  name: "like",
  data(){
    return{
        user:this.$store.state.user,
        userLike:[],
        search:'',
        pageInfo:{
          pageNum:1,
          pageSize:5
        }
    }
  },
  mounted() {
    this.init();
  },
  methods:{
    init(){
      let vm = this;
      this.axios({
        url:`/localhost/crad/likes?likeIds=${vm.user.liked}&pageNum=${vm.pageInfo.pageNum}&pageSize=${vm.pageInfo.pageSize}`,
        method:'get'
      }).then(function (res) {
        console.log(res.data);
        vm.userLike = res.data.data.list;
        vm.pageInfo = res.data.data;
      }).catch(function (err) {
        console.log(err)
      });
    },
    //分页
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.init();
    },

    //删除
    //查看详情信息
    handleDelete(index, row) {
      console.log(row);
      let vm = this;
      this.axios({
        url: `/localhost/user/like?userId=${vm.user.id}&card=${row.id}&like=${false}`,
        method:'get'
      }).then(function (res) {
        console.log(res.data);
        vm.user = res.data.data;
        vm.$store.commit('UpdateUser',res.data.data);
        vm.init();
      }).catch(function (err) {
        console.log(err)
      });
    },
  }
}
</script>

<style scoped>
.block{
  margin-top: 20px;
  text-align: center;
}
</style>
